package com.foreveredu.propms.domain;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OrderBy;
import javax.persistence.Table;

/**
 * Description:<br/>
 * 领域模型：房产类，一个楼栋包含多个房产<br/>
 * Date:<br/>
 * 2013/3/2<br/>
 * 
 * @author hushigang
 */

@Entity
@Table(name = "T_House")
public class House implements Serializable {

	private static final long serialVersionUID = 1L;
	private int id;
	private String houseId;// 房产编号
	private String name;// 房产名称
	private HouseType type;// 房屋类型，包括住宅、商铺（门面）
	private HouseSource source;// 房产来源，包括商品房、还建房、经济适用房
	private double area;// 房产面积
	private int unit;// 房产所在楼栋的单元数
	private int floor;// 房产所在楼栋的楼层数
	private Building building;// 房产所属楼栋
	private Owner owner;// 业主
	private int isReg;//是否已经登记，房产登记即为该房产指定收费项目
	private int isInit;// 是否已经执行初始化操作
	private String initDate;// 初始化日期
	private Set<ChargeItem> chargeItems;//该房产应缴纳的收费项目

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Column
	public String getHouseId() {
		return houseId;
	}

	public void setHouseId(String houseId) {
		this.houseId = houseId;
	}

	@Column
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column
	public double getArea() {
		return area;
	}

	public void setArea(double area) {
		this.area = area;
	}

	@Column
	public int getUnit() {
		return unit;
	}

	public void setUnit(int unit) {
		this.unit = unit;
	}

	@Column
	public int getFloor() {
		return floor;
	}

	public void setFloor(int floor) {
		this.floor = floor;
	}

	@ManyToOne
	@JoinColumn(name = "building_id")
	public Building getBuilding() {
		return building;
	}

	public void setBuilding(Building building) {
		this.building = building;
	}

	@ManyToOne(cascade=CascadeType.ALL)
	@JoinColumn(name = "owner_id")
	public Owner getOwner() {
		return owner;
	}

	public void setOwner(Owner owner) {
		this.owner = owner;
	}

	@ManyToOne
	@JoinColumn(name = "houseType_id")
	public HouseType getType() {
		return type;
	}

	public void setType(HouseType type) {
		this.type = type;
	}

	@ManyToOne
	@JoinColumn(name = "houseSource_id")
	public HouseSource getSource() {
		return source;
	}

	public void setSource(HouseSource source) {
		this.source = source;
	}

	@Column
	public int getIsReg() {
		return isReg;
	}

	public void setIsReg(int isReg) {
		this.isReg = isReg;
	}

	@Column
	public int getIsInit() {
		return isInit;
	}

	public void setIsInit(int isInit) {
		this.isInit = isInit;
	}

	@Column
	public String getInitDate() {
		return initDate;
	}

	public void setInitDate(String initDate) {
		this.initDate = initDate;
	}

	@ManyToMany(targetEntity = ChargeItem.class, cascade = { CascadeType.PERSIST,
		CascadeType.MERGE })
	@JoinTable(name = "T_House_ChargeItem", joinColumns = @JoinColumn(name = "house_id"), inverseJoinColumns = @JoinColumn(name = "chargeItem_id"))
	@OrderBy(value="id ASC")
	public Set<ChargeItem> getChargeItems() {
		return chargeItems;
	}

	public void setChargeItems(Set<ChargeItem> chargeItems) {
		this.chargeItems = chargeItems;
	}
	
}
